﻿using NAnt.Core;
using NAnt.Core.Attributes;

namespace Lean.NantTasks.Deployment
{
    /// <summary>
    /// Gives a certain nant-property another name. 
    /// Used in cases where we want to access a property whose name is depending on another property. 
    /// E.g. <alias name= "vdir" value="vdir.${deployment.target}" />	
    /// Its especially useful in connection with the jsonconfig-task
    /// </summary>
    [TaskName("alias")]
    public class AliasTask : Task
    {
        [TaskAttribute("name"), StringValidator(AllowEmpty = false)]
        public string Name { get; set; }

        [TaskAttribute("value"), StringValidator(AllowEmpty = false)]
        public string Value { get; set; }


        protected override void ExecuteTask()
        {
            if (!Properties.Contains(Value)) {
                var message = "There is not property set named \""+Value+"\"";
                //Log(Level.Error, message);
                throw new BuildException(message);
            }

            Properties[Name] = Properties[Value];
        }
    }
}